package com.zlq.cn.controller;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zlq.cn.api.SignApiResult;
import com.zlq.cn.entity.Zuowen;
import com.zlq.cn.service.un.ZuowenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 作文 前端控制器
 * </p>
 *
 * @author zhoucl
 * @since 2024-04-24
 */
@Api(tags = "公共-作文")
@RestController
@RequestMapping("/api/common/zuowen")
public class ZuowenController {

    @Resource
    private ZuowenService zuowenService;

    @ApiOperation("作文筛选")
    @GetMapping("/filter")
    public SignApiResult<List<JSONObject>> filterItem(Zuowen zuowen) {
        return SignApiResult.resultSuccess(zuowenService.filterItem(zuowen));
    }

    @ApiOperation("作文列表")
    @GetMapping("/list")
    public SignApiResult<Page<Zuowen>> list(Page<Zuowen> page, Zuowen zuowen) {
        zuowenService.lambdaQuery()
                .eq(StringUtils.isNotEmpty(zuowen.getGrade()), Zuowen::getGrade, zuowen.getGrade())
                .eq(StringUtils.isNotEmpty(zuowen.getType()), Zuowen::getType, zuowen.getType())
                .eq(StringUtils.isNotEmpty(zuowen.getYear()), Zuowen::getYear, zuowen.getYear())
                .eq(StringUtils.isNotEmpty(zuowen.getRegion()), Zuowen::getRegion, zuowen.getRegion())
                .eq(Zuowen::getCategory, zuowen.getCategory())
                .like(StringUtils.isNotEmpty(zuowen.getTitle()), Zuowen::getTitle, zuowen.getTitle())
                .page(page);
        return SignApiResult.resultSuccess(page);
    }
}

